<?php

namespace app\api\controller;

use app\admin\model\patrol\Inspection;
use app\admin\model\userstaff\UserClass;
use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 巡查街道
 */
class PatrolInspection extends Api
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new Inspection();
        $this->modelClass = new UserClass();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }

    /**
     * 根据用户所在城市进行划分 列表
     * @return void
     */
    public function list()
    {
        $input = input();
        $info = $this->auth->getUserinfo();
        try {
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];
            $data = $this->modelClass->classInfo($info['user_staff_class_id']);

            $pageArr = array_merge($pageArr, $input);
            $data = $this->model
                ->whereOr('user_staff_class_id',$info['user_staff_class_id'])
                ->whereOr('user_staff_class_id', 'in' ,$data['below'])
                ->order('weigh desc')
                ->paginate(['page' => $pageArr['page'] ?: 1, 'list_rows' => $pageArr['page_limit'] ?: 10]);
            $this->success('ok', $data);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }



}